<?php

namespace App\Repository;


use App\Models\Banner;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

/**
 * Class BannerRepository
 * @package App\Repository
 */
class BannerRepository
{
    /**
     * @var Banner
     */
    public $banner;

    /**
     * BannerRepository constructor.
     * @param Banner $banner
     */
    public function __construct(Banner $banner)
    {
        $this->banner = $banner;
    }

    /**
     * @param $id
     * @return array|mixed
     */
    public function getBanner($id)
    {
        try{
            return $this->banner->with('items')->findOrFail($id);
        }catch (\Exception $e){
            throw new NotFoundHttpException('请求的banner不存在，请检查bannerID', null ,40000);
        }
    }

}
